<template>
  <view class="container">
    <!-- 头部信息 -->
    <view class="header">
      <view class="greeting" v-if="userInfo.type==1" >你好，分店管理员</view>
	  <view class="greeting" v-else >你好</view>
      <view class="shop-name">店铺：{{userInfo.storeName?userInfo.storeName:'您还未登录'}}</view>
      <view class="staff-account">店员账号：{{userInfo.realname?userInfo.realname:''}}</view>
    </view>

    <!-- 核销模块 -->
    <view class="verification-module">
      <view class="input-group">
        <input 
          class="verification-input" 
          placeholder="请输入核销码" 
          v-model="verificationCode"
          placeholder-class="placeholder-style"
        />
        <view class="verification-btn" @click="handleVerification(verificationCode)">核销</view>
      </view>
    </view>

    <!-- 扫码核销按钮 -->
    <view class="scan-btn" @click="handleScan">
      <text>扫码核销</text>
    </view>
	<!-- <view @click="goLogin">登录</view> -->
	
  </view>
</template>

<script>
export default {
  data() {
    return {
      shopName: "XX分店",
      staffAccount: "admin123",
      verificationCode: "",
	  userInfo:'',
	  token:'',
    }
  },
  onLoad() {
  	
	this.userInfo=uni.getStorageSync("userInfo")
  },
  methods: {
	goLogin(){
	  uni.navigateTo({
	  	url:'login'
	  })
	},
    handleVerification(verificationCode) {
		this.token=uni.getStorageSync("token")
		if(!this.token){
			uni.reLaunch({
				url:'login'
			})
			return false
		}
      /* uni.showToast({
        title: `核销码: ${this.verificationCode}`,
        icon: 'none'
      }); */
      // 这里添加核销逻辑
	  this.$http('jeecg-boot/app/market/bicVerificationCode/verificationCode',{
	  	"code":verificationCode
	  },'POST').then(res => {
		  if(res.success){
				 uni.showToast({
					 title: '操作成功',
					 icon:'none',
					 duration: 3000,
				 });
				 setTimeout(function() {
					uni.navigateTo({
						url:'../order/orderDetail?orderId='+res.result
					})
				}, 1000); 
		  			
		  }else{
				 uni.showToast({
					 title: res.message,
					 icon:'none',
					 duration: 3000,
				 });
		}
	  })
    },
    handleScan() {
		this.token=uni.getStorageSync("token")
		if(!this.token){
			uni.reLaunch({
				url:'login'
			})
			return false
		}
	  var that=this;
      uni.scanCode({
		scanType:'qrCode',
      	success: function (res) {
      		console.log('条码类型：' + res.scanType);
      		console.log('条码内容：' + res.result);
			that.handleVerification(res.result)
      	},
		fail(err) {
			console.log(err)
		}
      });
    }
  },
  onShareAppMessage(){
	  
  }
}
</script>

<style>
/* 全局样式 */
.container {
  padding: 20px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  box-sizing: border-box;
}

/* 头部样式 */
.header {
  margin-bottom: 40px;
}
.greeting {
  font-size: 24px;
  font-weight: bold;
  color: #333;
  margin-bottom: 5px;
}
.description {
  font-size: 16px;
  color: #666;
  margin-bottom: 15px;
}
.shop-name {
  font-size: 20px;
  font-weight: bold;
  color: #333;
  margin-bottom: 5px;
}
.staff-account {
  font-size: 14px;
  color: #999;
}

/* 核销模块样式 */
.verification-module {
  margin-bottom: 30px;
}
.input-group {
  display: flex;
  align-items: center;
  border: 1px solid #eee;
  border-radius: 8px;
  overflow: hidden;
}
.verification-input {
  flex: 1;
  height: 50px;
  padding: 0 15px;
  font-size: 16px;
}
.placeholder-style {
  color: #ccc;
}
.verification-btn {
  width: 80px;
  height: 50px;
  background-color: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #333;
}

/* 扫码按钮样式 */
.scan-btn {
  height: 50px;
  border-radius: 25px;
  background: linear-gradient(to right, #4e8cff, #3a6cd9);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 18px;
  box-shadow: 0 4px 10px rgba(78, 140, 255, 0.3);
}
</style>